package com.control.qct.businesssteward;

import android.app.Application;
import android.content.Context;

import com.lzy.okgo.OkGo;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * Created by Administrator on 2018/2/27 0027.
 */

public class MyApplication extends Application {
    private static MyApplication instance;
    public static final long DEFAULT_MILLISECONDS = 30000;      //默认的超时时间

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        initOkGo();//初始化okgo
    }
    /**
     * 配置okGo全局参数
     */
    private void initOkGo() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        //全局的读取超时时间
        builder.readTimeout(DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS);
        //全局的写入超时时间
        builder.writeTimeout(DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS);
        //全局的连接超时时间
        builder.connectTimeout(DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS);
        OkGo.getInstance().init(this)                       //必须调用初始化
                .setOkHttpClient(builder.build())               //建议设置OkHttpClient，不设置将使用默认的
                .setRetryCount(0);                               //全局统一超时重连次数，默认为三次，那么最差的情况会请求4次(一次原始请求，三次重连请求)，不需要可以设置为0

    }

    /**
     * 获取全局Context
     * @return
     */
    public static Context getMyApplicationContext() {
        return instance;
    }

}
